package com.hskn.hss.entity;

import com.hskn.hss.constant.CommonConstant;

public class AjaxResult<T> {
    private boolean success;
    private String message;
    private Integer code;
    private T result;
    private long timestamp = System.currentTimeMillis();

    public AjaxResult() {
    }

    public AjaxResult(boolean success, String message, Integer code, T result) {
        this.success = success;
        this.message = message;
        this.code = code;
        this.result = result;
    }

    public static AjaxResult<Object> success() {
        return success(null);
    }

    public static AjaxResult<Object> success(Object data) {
        AjaxResult<Object> r = new AjaxResult<>();
        r.setCode(CommonConstant.SC_OK_200);
        r.setMessage(CommonConstant.SC_OK_MSG);
        r.setResult(data);
        r.setSuccess(true);
        return r;
    }

    public static AjaxResult<Object> fail() {
        return fail(CommonConstant.SC_NG_MSG);
    }

    public static AjaxResult<Object> fail(String msg) {
        AjaxResult<Object> r = new AjaxResult<>();
        r.setCode(CommonConstant.SC_NG_400);
        r.setMessage(msg);
        r.setSuccess(false);
        return r;
    }

    public static AjaxResult<Object> fail(String msg, Integer code) {
        AjaxResult<Object> r = new AjaxResult<>();
        r.setCode(code);
        r.setMessage(msg);
        r.setSuccess(false);
        return r;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }
}
